package com.iotechn.unimall.plugin.core.inter;

import com.iotechn.unimall.core.exception.ServiceException;
import com.iotechn.unimall.data.domain.UserDO;
import com.iotechn.unimall.data.dto.order.OrderDTO;
import com.iotechn.unimall.data.mapper.UserMapper;
import com.unimall.graded.app.api.customer.CustomerService;
import com.unimall.graded.app.api.customer.CustomerServiceImpl;
import com.unimall.graded.data.domain.CustomerDO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sun.rmi.runtime.Log;

import java.rmi.ServerException;
import java.util.Date;
@Component
public class PluginAddCustomerAfterAddUser extends  AbstractPlugin implements IPluginAddCustomer {
    private static final Logger logger = LoggerFactory.getLogger(PluginAddCustomerAfterAddUser.class);
    @Autowired
    public CustomerService customerService;

    @Override
    public void installPlugin() throws Exception {

    }

    @Override
    public String getTag() {
        return null;
    }

    @Override
    public String getSign() {
        return null;
    }

    @Override
    public boolean invokeAddCustomer(UserDO userDO, Long parentId) throws ServiceException{

        CustomerDO customerDO = new CustomerDO();
        customerDO.setUserId(userDO.getId());
        customerDO.setNickname(userDO.getNickname());
        customerDO.setParentId(parentId);

        try {

            customerService.addCustomer(customerDO);
        }catch (ServiceException e){
            throw e;
        }

        return true;
    }

    @Override
    public void afterPropertiesSet() throws Exception {

    }
}
